@extends('admin.layouts.application')


@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">品牌管理</strong> /
                    <small>Brand</small>
                </div>
            </div>

            <hr>


            @include('admin.layouts._flash')


            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a class="am-btn am-btn-default" href="{{route('admin.brand.create')}}">
                                <span class="am-icon-plus"></span> 新增
                            </a>
                            <button type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除
                            </button>
                        </div>
                    </div>
                </div>

                <div class="am-u-sm-12 am-u-md-3">
                    <form action="{{route('admin.brand.index')}}" method="get">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" class="am-form-field" name="keyword"  value="{{Request::input('keyword')}}">
                          <span class="am-input-group-btn">
                            <button class="am-btn am-btn-default" type="submit">搜索</button>
                          </span>
                        </div>
                    </form>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check">
                                    <input type="checkbox"/>
                                </th>
                                <th class="table-id">编号</th>
                                <th>缩略图</th>
                                <th class="table-title">名称</th>
                                <th class="table-type">网址</th>
                                <th class="table-desc am-hide-sm-only">品牌描述</th>
                                <th class="table-is-show am-hide-sm-only">是否显示</th>
                                <th class="am-hide-sm-only">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($brands as $brand)

                                <tr data-id="{{$brand->id}}">
                                    <td><input type="checkbox"/></td>
                                    <td>{{$brand->id}}</td>
                                    <td><img src="{{$brand->thumb}}" style="max-height: 100px;max-width: 100px;"><a href="#"></a></td>
                                    <td>{{$brand->name}}</td>
                                    <td class="am-hide-sm-only">

                                    <a href="{{$brand->url}}" target="_blank">{{$brand->url}}</a></td>
                                    <td class="am-hide-sm-only">{{$brand->desc}}</td>

                                    <td class="am-hide-sm-only">{!! is_something('is_show', $brand) !!}</td>
                                    <td class="am-hide-sm-only">
                                        <input type="text" value="{{$brand->sort_order}}" name="sort_order">
                                    </td>

                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                   href="{{route('admin.brand.edit', $brand->id)}}">
                                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                   href="{{route('admin.brand.destroy', $brand->id)}}"
                                                   data-method="delete" data-token="{{csrf_token()}}"
                                                   data-confirm="确认删除吗?">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$brands->total()}} 条记录
                            <div class="am-fr">
                                {!! $brands->links() !!}
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
@endsection
@section('js')
    <script type="text/javascript">
        $(function () {

                //排序
                $("input[name='sort_order']").change(function () {

                    var data = {
                        sort_order: $(this).val(),

                        id: $(this).parents("tr").data('id')
                    }

                    $.ajax({
                        type: "PATCH",
                        url: "/admin/brand/sort_order ",
                        data: data
                    });
                })

            //是否...
            $(".is_something").click(function () {
                var _this = $(this);
                var data = {
                    id: _this.parents("tr").data('id'),
                    attr: _this.data('attr')
                }
                console.log(data);

                $.ajax({
                    type: "PATCH",
                    url: "/admin/brand/is_something",

                    data: data,
                    success: function () {
                        _this.toggleClass('am-icon-close am-icon-check');
                    }
                });
            });
        });
    </script>
@endsection